<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: DynamicScaffoldResource::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">DynamicScaffoldResource::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/lib/dynamic_scaffold_resource_rb.html">
                lib/dynamic_scaffold_resource.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="ClassMethods.html">ClassMethods</a> is a convention for wrapping
methods to mixin to a class.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000011">scaffold_resource</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">scaffold_resource</span><span class="method-args">(model_id, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The method that does the work, called as &quot;<tt><a
href="ClassMethods.html#M000011">scaffold_resource</a>
:resource</tt>&quot;. Emulates the &quot;scaffold :model&quot; call, but
does it with the RESTful actions. You need to view the source outside of
rdoc to see the methods it adds, because rdoc can&#8216;t parse the big
module_eval&#8216;ed string.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
    <span class="ruby-comment cmt"># File lib/dynamic_scaffold_resource.rb, line 10</span>
10:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scaffold_resource</span>(<span class="ruby-identifier">model_id</span>, <span class="ruby-identifier">options</span> = {})
11:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">assert_valid_keys</span>(<span class="ruby-identifier">:class_name</span>)
12:       
13:       <span class="ruby-identifier">singular_name</span> = <span class="ruby-identifier">model_id</span>.<span class="ruby-identifier">to_s</span>
14:       <span class="ruby-identifier">plural_name</span>   = <span class="ruby-identifier">singular_name</span>.<span class="ruby-identifier">pluralize</span>
15:       <span class="ruby-identifier">class_name</span>    = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:class_name</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">singular_name</span>.<span class="ruby-identifier">camelize</span>
16:       <span class="ruby-identifier">models_path</span>   = <span class="ruby-identifier">plural_name</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;_path&quot;</span>
17:       <span class="ruby-identifier">model_path</span>    = <span class="ruby-identifier">singular_name</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;_path&quot;</span>
18:       <span class="ruby-identifier">new_model_path</span> = <span class="ruby-node">&quot;new_#{singular_name}_path&quot;</span>
19:       <span class="ruby-identifier">edit_model_path</span> = <span class="ruby-node">&quot;edit_#{singular_name}_path&quot;</span>
20:       
21:       <span class="ruby-identifier">module_eval</span> <span class="ruby-value str">&quot;# GET /models\n# GET /models.xml\ndef index #:doc:\n@\#{plural_name} = \#{class_name}.find(:all)\nrespond_to do |format|\nformat.html {render_scaffold('index')}\nformat.xml  { render :xml =&gt; @\#{plural_name}.to_xml }\nend\nend\n\n# GET /models/1\n# GET /models/1.xml\ndef show\n@\#{singular_name} = \#{class_name}.find(params[:id])\n\nrespond_to do |format|\nformat.html {render_scaffold}# show.rhtml\nformat.xml  { render :xml =&gt; @\#{singular_name}.to_xml }\nend\nend\n\n# GET /models/new\ndef new\n@\#{singular_name} = \#{class_name}.new\nrender_scaffold\nend\n\n# GET /models/1;edit\ndef edit\n@\#{singular_name} = \#{class_name}.find(params[:id])\nrender_scaffold\nend\n\n# POST /models\n# POST /model.xml\ndef create\n@\#{singular_name} = \#{class_name}.new(params[\&quot;\#{singular_name}\&quot;.to_sym])\n\nrespond_to do |format|\nif @\#{singular_name}.save\nflash[:notice] = '@\#{singular_name} was successfully created.'\n\nformat.html { redirect_to \#{model_path}(@\#{singular_name}) }\nformat.xml do\nheaders[\&quot;Location\&quot;] = \#{model_path}(@\#{singular_name})\nrender :nothing =&gt; true, :status =&gt; \&quot;201 Created\&quot;\nend\nelse\nformat.html { render_scaffold(\&quot;new\&quot;) }\nformat.xml  { render :xml =&gt; @\#{singular_name}.errors.to_xml }\nend\nend\nend\n\n# PUT /models/1\n# PUT /models/1.xml\ndef update\n@\#{singular_name} = \#{class_name}.find(params[:id])\n\nrespond_to do |format|\nif @\#{singular_name}.update_attributes(params[:\#{singular_name}])\nformat.html { redirect_to \#{model_path}(@\#{singular_name}) }\nformat.xml  { render :nothing =&gt; true }\nelse\nformat.html { render_scaffold(\&quot;edit\&quot;) }\nformat.xml  { render :xml =&gt; @\#{singular_name}.errors.to_xml }\nend\nend\nend\n\n# DELETE /models/1\n# DELETE /models/1.xml\ndef destroy\n@\#{singular_name} = \#{class_name}.find(params[:id])\n@\#{singular_name}.destroy\n\nrespond_to do |format|\nformat.html { redirect_to \#{models_path} }\nformat.xml  { render :nothing =&gt; true }\nend\nend\n\nprivate\n\ndef render_scaffold(action=nil)\naction ||= caller_method_name(caller)\n# logger.info (\&quot;testing template:\&quot; + \&quot;\\\#{self.class.controller_path}/\\\#{action}\&quot;) if logger\n\nif template_exists?(\&quot;\\\#{self.class.controller_path}/\\\#{action}\&quot;)\nrender :action =&gt; action\nelse\n@scaffold_class = \#{class_name}\n@scaffold_singular_name, @scaffold_plural_name = \&quot;\#{singular_name}\&quot;, \&quot;\#{plural_name}\&quot;\n@scaffold_models_path = @template.method(\&quot;\#{models_path}\&quot;)\n@scaffold_model_path = @template.method(\&quot;\#{model_path}\&quot;)\n@scaffold_new_model_path = @template.method(\&quot;\#{new_model_path}\&quot;)\n@scaffold_edit_model_path = @template.method(\&quot;\#{edit_model_path}\&quot;)\nadd_instance_variables_to_assigns\n@template.instance_variable_set(\&quot;@content_for_layout\&quot;, @template.render_file(scaffold_path(action), false))\nif !active_layout.nil?\nrender :file =&gt; active_layout, :use_full_path =&gt; true\nelse\nrender :file =&gt; scaffold_path('layout')\nend\nend\nend\ndef scaffold_path(template_name)\nFile::join RAILS_ROOT, \&quot;vendor/plugins/dynamic_scaffold_resource/lib/templates/\&quot; + template_name + \&quot;.rhtml\&quot;\nend\ndef caller_method_name(caller)\ncaller.first.scan(/`(.*)'/).first.first # ' ruby-mode\nend\n&quot;</span>, <span class="ruby-keyword kw">__FILE__</span>, <span class="ruby-keyword kw">__LINE__</span>
22:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>